<template>
	<div class="port-page">
		<!-- 顶部按钮 -->
		<div class="but1">
			<router-link to="/home">
				<el-button type="warning" size="mini" style='margin-right: 5px;' icon="el-icon-menu">首页</el-button>
			</router-link>
			<router-link :to="{path:'/home',query: {id:vbjid,frompage:'ks'}}">
				<el-button type="warning" size="mini" icon="el-icon-caret-left">返回</el-button>
			</router-link>
			<div class="search-item">
				<span>考试类型</span>
				<el-select v-model="vcdname" @change="search()" class="code-search" placeholder="请选择考试类型">
					<el-option :label="v.cdname" :value="v.cdname" v-for="v in comcdlist"></el-option>
				</el-select>

			</div>
			<span v-if="showbut">
				<el-button type="success" size="small" @click='iscanedit=true' v-if="!iscanedit" >启用编辑</el-button>
				<el-button type="danger" size="small" @click='iscanedit=false' v-if="iscanedit" >关闭编辑</el-button>
				<el-button type="success" size="small" @click='fstj()' v-if="iscanedit" >提交分数</el-button>
			</span>
		</div>
		<div class="search">
		</div>
		<!-- 数据表格展示区域 -->
		<el-table :data="dataList" stripe border size="small" align="center" class="admin-table" @select="checkSelect" @select-all="checkall">
			<div slot='empty'>
				<img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
				<span style="vertical-align: middle;">暂时还没有内容哦!</span>
			</div>
			<el-table-column :prop="v.prop" :label="v.label" v-for="(v,index) in portTitleList" align="center" show-overflow-tooltip v-if="v.hide != 0" :formatter="v.formatter" :align="v.align || 'center'" :fixed="v.fixed" :class-name="v.columnStyle" :width="v.width" :min-width="v.minWidth" :header-align="v.headerAlign || 'center'">
				<template scope="scope">
					<div slot="reference" :style="tableCellControl(scope)" v-if="scope.column.property == 'fs' && iscanedit ">
						<el-input class="content-input" @focus="focus($event)" v-model="scope.row[scope.column.property]"></el-input>
					</div>
					<div slot="reference" v-else>
						{{ scope.row[scope.column.property] }}
					</div>
				</template>
			</el-table-column>
			<el-table-column label="操作" width="230px" align="center" v-if="!iscanedit">
				<template scope="scope">
					<el-button size="mini" type="success" @click="componentsShow('info',scope)">学生详情</el-button>
					<el-button size="mini" type="primary" v-if="scope.row.zt == '未安排补课'"  @click="componentsShow('buke',scope)">补课</el-button>
					<el-button size="mini" type="danger" disabled v-if="scope.row.zt == '已安排补课'">已安排补课</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!-- 各个组件显示区域 -->
		<!-- 动画加载 -->
		<LoadingComponent v-show="isLoading"></LoadingComponent>
		<!-- info组件 -->
		<infoComponent v-if="portComponents.info.toggle" @close="componentsHide" :params="portComponents.info.params"></infoComponent>

		<BukeComponent v-if="portComponents.buke.toggle" @close="componentsHide" :params="portComponents.buke.params"></BukeComponent>
		<!-- 子路由显示区域 -->
		<router-view class="port-view"></router-view>
	</div>
</template>
<script>
	import { mapState } from 'vuex'
	import LoadingComponent from 'components/loading'
	import BukeComponent from 'components/xzhomezj/buke/bkap'
	import InfoComponent from 'view/educa/classManage/student/info'
	import qs from 'qs'
	export default {
		components: {
			LoadingComponent,
			InfoComponent,
			BukeComponent
		},
		data() {
			return {

				/*模糊搜索条件*/

				vcdname: '',
				vbjid: this.$route.query.iid + '', // 班级id
				showbut:false,

				iscanedit: false, //显示编辑的数字框

				multipleDelNum: '', //获取批量选择的数据
				dataList: [], //表格数据
				comboxlist: [], //下拉框 动态的
				comcdlist: [],
				vcomautovalue: '', //下拉框name 动态的
				vcomgdvalue: '', //下拉框name 固定的

				/*动画加载*/
				isLoading: true, //动画加载
				searchLoading: false, //搜索按钮触发按钮动画
				/*分页属性设置*/
				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: this.$store.state.pageindex, //当前分页页码
				pagesizes: this.$store.state.pagesizes, //显示个数的选择器选项
				pagesize: this.$store.state.pagesize, //每页显示条目数
				total: 0, //总条数

				/*组件区域*/
				portComponents: {
					/* 添加 */
					buke: {
						type: 'buke',
						toggle: false,
						params: '',
						data: {}
					},
					/* info */
					info: {
						type: 'info',
						toggle: false,
						params: '',
						data: {}
					}
				},
				/*
				    prop :  接口参数名
				    label : 接口中文名
				    hide : 是否隐藏这一列
				    align : 这一列对齐顺序 ： left,right,center
				    headerAlign : 这一列表头对齐方式 ： left,right,center
				*/
				portTitleList: [

					{
						prop: 'id',
						label: 'id',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'bjmc',
						label: '班级名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'zwm',
						label: '学生中文名',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'ename',
						label: '学生英文名',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'xsid',
						label: '学生id',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'lsmc',
						label: '老师名称',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'ksid',
						label: '考试记录',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'fs',
						label: '考生成绩',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'crtime',
						label: '第一次修改时间',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'uptime',
						label: '登记日期',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					}
				]
			}
		},
		created() {
			//加载页面时调用
			this.$store.dispatch('changeTitle', this.$route.query.bjmc + '考试成绩'); //修改title
			this.$store.dispatch('changeRouterIndex', '/educa/kscj'); //修改路由
			this.search(); //分页获取默认数据
			this.getcomlist(); //加载下拉列表
			this.getcdlist();
			this.isLoading = true; //动画开始
		},
		mounted() {
			//加载完成之后event
			this.isLoading = false; //动画结束
		},
		methods: {
			focus(event) {
		     event.currentTarget.select();
		   },
			fstj(lxtype) {
				this.$confirm('确认要提交分数么?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					// lxtype  1 =主教 2=助教
					var qkstr = "";
					var es = this
					this.dataList.forEach(function(v, i) {
						qkstr = v.xsid + "," + v.fs + ";" + qkstr;
					})
					if(qkstr == '') {
						this.$message.warning('没有找班级学生,不能提交分数');
						return;
					}
					var logininfo = JSON.parse(localStorage.logininfo);
					var params2 = qs.stringify({
						yhid: logininfo.id,
						xxid: logininfo.xxid,
						bjid: this.vbjid, // 班级id
						kslx: this.vcdname, //课次
						qkstr: qkstr
					})
					//执行
					this.axios.post(this.$store.state.api + 'ksscore/updatecj', params2)
						.then(res => {
							if(res.data.code == 1) {
								this.search();
								this.iscanedit = false;
							} else {
								this.$message.warning(res.data.msg)
							}
						})

				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消'
					});
				});

			},
			search() {
				//查询搜索触发事件
				var logininfo = JSON.parse(localStorage.logininfo);
				this.searchLoading = true;
				var params2 = qs.stringify({
					//                    keyword: this.vkeyword, // keyword
					bjid: this.vbjid, // 班级id
					kslx: this.vcdname, // 考试类型
					yhid: logininfo.id,
					xxid: logininfo.xxid
				})
				//执行
				this.axios.post(this.$store.state.api + 'ksscore/list3', params2)
					.then(res => {
						let data = res.data.data;
						let list = data.list;
						this.total = data.totalPage;
						this.dataList = list;
						if(this.dataList.length>0){
							this.showbut = true
						}
						this.searchLoading = false;
					}).catch(res => {})
			},
			getcomlist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				this.searchLoading = true;
				var params2 = qs.stringify({
					yhid: logininfo.id,
					xxid: logininfo.xxid
				})
				//执行
				this.axios.post(this.$store.state.api + 'bj/getbj', params2)
					.then(res => {
						let data = res.data.data;
						let list = data.list;
						this.comboxlist = list;
					}).catch(res => {})
			},
			getcdlist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				this.searchLoading = true;
				var params2 = qs.stringify({
					yhid: logininfo.id,
					xxid: logininfo.xxid,
					isenable: 'Y',
					pcd: 'c006'
				})
				//执行
				this.axios.post(this.$store.state.api + 'xxcode/list', params2)
					.then(res => {
						let data = res.data.data;
						let list = data.list;
						this.comcdlist = list;
					}).catch(res => {})
			},
			tableCellControl(scope) {
				//表格单元格控制CSS样式
				/*if (scope.row.id == 112 && scope.column.property == "iname") {
				    return {
				        color:"red",
				    }
				}else{
				    return {
				        color:"green",
				    }
				}*/
			},
			handleSizeChange(val) { //每页显示条数触发事件
				this.pagesize = val;
				this.pageindex = 1;
				this.search();
			},
			handleCurrentChange(val) { //分页触发事件
				this.search();
			},
			checkSelect(selection, row) { //点击单选select触发事件
				console.log(selection, row)
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			checkall(selection) { //点击全选select触发事件
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件
				console.log(type, data)
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;
						if(this.portComponents[i].data.type == 'single') {
							this.portComponents[i].data.index = data.row.id
						} else if(this.portComponents[i].data.type == 'multiple') {
							this.portComponents[i].data.index = this.multipleDelNum;
						} else {
							return;
						}
						return;
					}
				}
			},
			componentsHide(setting) { //关闭组件
				console.log(setting)
				this.search();
				this.portComponents.buke.toggle = false
				for(let i in this.portComponents) {
					if(setting.type == this.portComponents[i].type) {
						this.portComponents[i].toggle = false;
						if(!setting.cancel) {
							this.search();
						}
						return;
					}
				}
			}
		},
		computed: {
			...mapState([
				'api' //域名
			]),
			multipleDeleteDisabled() {
				console.log(this.multipleDelNum)
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.port-page {
		font-size: 12px;
		/*.btn {
            height: 30px;
            padding:0 10px;
        }*/
		.code-search {
			height: 30px;
			margin: 10px 0 10px 0;
			min-width: 120px;
			max-width: 150px;
		}
		.class-page {
			text-align: left;
			margin-top: 10px;
		}
		.search-item {
			display: inline-block;
		}
		.but1 {
			width: 70%;
			float: left;
			margin-top: 8px;
		}
		.search {
			width: 30%;
			float: right;
			text-align: right;
		}
		.el-button+.el-button {
			margin-left: 5px;
		}
	}
</style>